package pro1.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import pro1.model.ResponseBody;
import pro1.service.CharacterService;

@RestController
@RequestMapping("cha")
public class CharacterController {
	
	@Autowired
	CharacterService characterService;
	/**
	 * 查询所有
	 * 
	 * @return
	 */
	@GetMapping("all")
	public ResponseBody all() {

		return characterService.all();
	}

	/**
	 * 添加或更新
	 * 
	 * @param depId
	 * @param name
	 * @param info
	 * @return
	 */
	@PostMapping("addOrUpdate")
	public ResponseBody addOrUpdateDep(@RequestParam(value = "chaId", required = false) Integer chaId,
			@RequestParam(value = "name", required = false) String name,
			@RequestParam(value = "info", required = false) String info) {

		return characterService.addOrUpdateDep(chaId, name, info);
	}

	/**
	 * 删除
	 * 
	 * @param depId
	 * @return
	 */
	@PostMapping("delete")
	public ResponseBody deleteDep(@RequestParam(value = "chaId", required = true) Integer chaId) {

		return characterService.deleteDep(chaId);
	}
	
	/**
	 * 设置权限
	 * @param chaId
	 * @param modules
	 * @return
	 */
	@PostMapping("setModules")
	public ResponseBody setModules(@RequestParam(value = "chaId", required = true) Integer chaId,
			@RequestParam(value = "modules", required = true) List<Integer> modules) {
		
		return characterService.setModules(chaId,modules);
	}
}
